import { IsNumber, IsString } from 'class-validator'
import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm'
import { Question } from './question.entity'

/**
 * 问卷提交记录
 */
@Entity('question_record')
export class QuestionRecord {
  @PrimaryGeneratedColumn()
  @IsNumber()
  questionRecordId?: number

  /**
   * 用户UID
   */
  @Column()
  @IsString()
  userUid: string

  /**
   * 总得分
   */
  @Column()
  @IsNumber()
  totalScore: number

  /**
   * 问卷 ID
   */
  @Column()
  @IsNumber()
  questionId: number

  /**
   * 问卷
   */
  @ManyToOne(() => Question, question => question.questionId)
  @JoinColumn({ name: 'questionId' }) // 显式绑定列名
  question: Question

  @CreateDateColumn()
  createdAt?: Date

  @UpdateDateColumn()
  updatedAt?: Date
}
